{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a1 = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from SubFunc import printID\n",
    "\n",
    "a2 = a3 = a4 = 4\n",
    "printID(a2, a3, a4)  # 变量的值的ID相同"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2, Type: <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "from SubFunc import printType\n",
    "\n",
    "b1 = 0\n",
    "b1 += 2  # 这样会节省内存\n",
    "printType(b1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"True and False:\", True and False)\n",
    "print(\"False and True:\", False and True)\n",
    "print(\"True and True:\", True and True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"True or False:\", True or False)\n",
    "print(\"False or True:\", False or True)\n",
    "print(\"False or False:\", False or False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"not (True):\", not (True))\n",
    "print(\"not (False):\", not (False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"in:\", \"a\" in \"abc\")  # 判断是否在里面\n",
    "print(\"not in:\", \"d\" not in \"abc\")  # 判断是否不再里面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x1 = 100\n",
    "x2 = 100\n",
    "print(x1 == x2)  # 判断两个值是否相等\n",
    "printID(x1, x2)\n",
    "print(\n",
    "    \"x1 is x2:\", x1 is x2\n",
    ")  # 可以快速判断两个变量的值的内存地址(id)是否相等;不可变的类型的值相同时,ID相同\n",
    "print(\"id(x1) == id(x2):\", id(x1) == id(x2))  # 等价的写法\n",
    "x3 = [1, 2]\n",
    "x4 = [1, 2]\n",
    "print(\"x3 == x4:\", x3 == x4)\n",
    "printID(x3, x4)\n",
    "print(\"x3 is x4:\", x3 is x4)  # 列表是可变类型,值相同的时候,ID却不同"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c1 = \"1\" + \"2\"\n",
    "printType(c1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "d1 = 1 != 2\n",
    "printType(d1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
